<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

include_once('Admin.php');
$NAVIFILE = "../config/navigation.php";
if(!empty($_POST)){
	foreach ($_POST['sName'] as $i => $x){
		$sShow = is_numeric($_POST['sShow'][$i]) ? $_POST['sShow'][$i] : 0;
		$sSort = is_numeric($_POST['sSort'][$i]) ? $_POST['sSort'][$i] : 99;
		if($_POST['sModu'][$i] == 7){
			$arran = explode('|',$_POST['sName'][$i]);
			$_POST['sName'][$i] = $arran[0];
			$_POST['sHURL'][$i] = $_POST['sDURL'][$i] = $arran[1];
		}		
		$sName = htmlspecialchars(stripcslashes($_POST['sName'][$i]),ENT_QUOTES);
		$sName = str_replace(');','',$sName); //防止数据中填写有");"，导致数据出错
		$result = "'sModu' => '{$_POST['sModu'][$i]}',";
		$result .= "'sShow' => '{$sShow }',";
		$result .= "'sNCid' => '{$_POST['sNCid'][$i]}',";
		$result .= "'sName' => '{$sName}',";
		$result .= "'sHURL' => '{$_POST['sHURL'][$i]}',";
		$result .= "'sDURL' => '{$_POST['sDURL'][$i]}',";
		$result .= "'sSort' => '{$sSort}'";
		$results .= "	array({$result}),\r\n";
	}
	$results = '$navigation' . $Lang . ' = array(' . "\r\n" . $results . ");";
	
	//conifg.js文件中写入导航相当配置参数
	$oVar['na'] = array('var CONFIG_NAVIGATION' . $Lang);
	$xva = $_POST['isDown'] == 'yes' ? "1," : "0,"; //是否开启功能
	$xva .= is_numeric($_POST['menu_top']) ? "{$_POST['menu_top']}," : "0,"; //上偏移量
	$xva .= is_numeric($_POST['menu_left']) ? "{$_POST['menu_left']}," : "0,"; //左偏移量
	$cc = $ss = NULL;
	foreach($_POST['sNCid'] as $i => $n){
		if($_POST['sModu'][$i] != 7 && $_POST['sModu'][$i] != 5 && $n == 0 && $_POST['sShow'][$i] == 1) $ss .= $_POST['sModu'][$i].'|';
		if($n != 0 && $_POST['sShow'][$i] == 1) $cc .= $n.'|';
	}
	$xva .= rtrim($ss,'|').','.rtrim($cc,'|');
	$oVar['va'] = array($xva);	
	if(($xxo = $admin->updatevar('../config/config.js',$oVar)) !== true) MsgBox (1,$xxo,'1');
	//config.js END	
	
	$fp = fopen($NAVIFILE,'r'); 
	@$conf_file = fread($fp,filesize($NAVIFILE));
	$conf_file = preg_replace('/\$navigation' . $Lang . '\s*\=.*?(\)+)(\;+)/is',$results,$conf_file,1); //$navigation
	$conf_file = preg_replace("/$CONFIG_NAVIGATION". $Lang ."\s*\=\s*[\"'].*?[\"']/is","$CONFIG_NAVIGATION". $Lang ." = \"" . $xva . "\"",$conf_file); //$CONFIG_NAVIGATION
	if(!@$fp = fopen($NAVIFILE,'w')) MsgBox(1,"没有写入 $NAVIFILE 的权限！","1");
	$fw = fwrite($fp,$conf_file);
	fclose($fp);
	
	AdminLog(1,1,'修改模板导航栏，结果：操作成功！');
	MsgBox (1,'导航栏修改成功！','1');
}

include_once($NAVIFILE);
$navigation = ${'navigation'.$Lang};
foreach ($navigation as $key => $row) {
    $volume[$key]  = $row['sSort'];
}
array_multisort($volume,SORT_ASC,$navigation); //排序
$CONFIG_NAVIGATION = explode(',',${'CONFIG_NAVIGATION'.$Lang});
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script src="../js/csshovernotie6.js" type="text/javascript"></script>
</head>
<body>
<br />
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr class="Notodd">
		<td><?php TopLang("dir={$_GET['dir']}&");?></td>
	</tr>
</table>
<form action="" method="post" name="NouForm">
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
  <tr>
    <td colspan="4" align="center" class="Main_Title"><?php echo $TemName?>导航栏设置<?php echo $OnWebLangName?></td>
  </tr>
  <tr class="odd">
    <td height="20" align="center"><strong>所属模块</strong></td>
    <td align="center"><strong>导航栏显示名称(URL)</strong></td>
    <td align="center"><strong>是否启用</strong></td>
    <td align="center"><strong>排序(升序)</strong></td>
  </tr>
<?php
$sModuArray = array('首页','产品','新闻','反馈','留言','内容','下载','自定义'); //(0首页,1产品,2新闻,3反馈,4留言,5内容,6下载,7自定义导航)
// 非内容模块[从模板文件中获取]
$ni = $Custom7 = 0; //复选框没选时无提交
$xLang = $Lang == 1 ? NULL : "/l{$Lang}";
foreach ($navigation as $i => $row){
	if($row['sNCid'] == 0){
		$isShowText = $row['sShow'] == 1 ? '<input name="sShow[' . $ni . ']" type="checkbox" value="1" checked />' : '<input name="sShow[' . $ni . ']" type="checkbox" value="1" />';
		switch ($row['sModu']){
			case 0 : $sHURL = $Lang==1 ? './home' : './html/index'; $sDURL = ($Lang==1 && $WebLangDefault==1) ? './' : "./?l{$Lang}/";	break;
			case 1 : $sHURL = "./html/products/index"; $sDURL = "./?fproducts{$xLang}"; break;
			case 2 : $sHURL = "./html/news/index"; $sDURL = "./?fnews{$xLang}"; break;
			case 3 : $sHURL = "./html/feedback/index"; $sDURL = "./?ffeedback{$xLang}"; break;
			case 4 : $sHURL = "./html/guestbook/index"; $sDURL = "./?fguestbook{$xLang}"; break;
			case 6 : $sHURL = "./html/download/index"; $sDURL = "./?fdownload{$xLang}"; break;
			case 7 :
				$row['sName'] .= '|' . $row['sHURL']; 
				$Custom7 ++; //统计当前模板导航栏配置文件中有多少个自定义导航
				break;
		}
		if($row['sModu'] == 7 && $Custom7 > $CustomNavigation) continue; //导航栏配置文件中的自定义数大于设定值，跳出循环
		$sHURL .= $Lang <= 1 ? '.html' : "{$Lang}.html";
		echo "<tr class=\"odd\">
		<td align=\"center\">{$sModuArray[$row['sModu']]}</td>
		<td height=\"20\" align=\"center\"><input name=\"sName[]\" type=\"text\" value=\"{$row['sName']}\" style=\"width:250px;\" /></td>
		<td align=\"center\">{$isShowText}</td>
		<td align=\"center\"><input name=\"sSort[]\" type=\"text\" value=\"{$row['sSort']}\" style=\"width:40px;\" />
		<input name=\"sModu[]\" type=\"hidden\" value=\"{$row['sModu']}\" />
		<input name=\"sNCid[{$ni}]\" type=\"hidden\" value=\"0\" />
		<input name=\"sHURL[]\" type=\"hidden\" value=\"{$sHURL}\" />
		<input name=\"sDURL[]\" type=\"hidden\" value=\"{$sDURL}\" />
		</td></tr>";
		$ni ++;
	}
}

// 合并

// 内容模块[同步数据库中一级内容栏目]
//$ni = 0; 
$SQL = "SELECT `ID`,`ColumnName` FROM `{$dbprefix}column` WHERE `ColumnType` = 0 && `ColumnLang` = $Lang && `ColumnLevel` = 1 ORDER BY `ID` ASC";
$sRs = $db -> SelectSQL($SQL);
foreach ($sRs as $i => $row){
	$nColumnName = $row['ColumnName'];
	$isShowText = '<input name="sShow[' . $ni . ']" type="checkbox" value="1" />';
	$oSort = $row['sSort'];
	foreach ($navigation as $x => $or){
		if($or['sNCid'] == $row['ID']){ //当前栏目已在配置文件中存在
			if($or['sShow'] == 1) $isShowText = '<input name="sShow[' . $ni . ']" type="checkbox" value="1" checked />';
			$nColumnName = $or['sName'];
			$oSort = $or['sSort'];
		}			
	}
	$sHURL = "./html/page/{$row['ID']}.html";
	$sDURL = "./?fpage{$xLang}/c{$row['ID']}";
	echo "<tr class=\"odd\">
	<td align=\"center\">{$sModuArray[5]} ({$row['ColumnName']})</td>
	<td height=\"20\" align=\"center\"><input name=\"sName[]\" type=\"text\" value=\"{$nColumnName}\" style=\"width:250px;\" /></td>
	<td align=\"center\">{$isShowText}</td>
	<td align=\"center\"><input name=\"sSort[]\" type=\"text\" value=\"{$oSort}\" style=\"width:40px;\" />
	<input name=\"sModu[]\" type=\"hidden\" value=\"5\" />
	<input name=\"sNCid[{$ni}]\" type=\"hidden\" value=\"{$row['ID']}\" />
	<input name=\"sHURL[]\" type=\"hidden\" value=\"{$sHURL}\" />
	<input name=\"sDURL[]\" type=\"hidden\" value=\"{$sDURL}\" />
	</td></tr>";
	$ni ++;	
}

	//循环结束检测是否有新增自定义导航栏
	for($xx=0; $xx<($CustomNavigation - $Custom7); $xx++){
		echo "<tr class=\"odd\">
		<td align=\"center\">{$sModuArray[7]}</td>
		<td height=\"20\" align=\"center\"><input name=\"sName[]\" type=\"text\" value=\"\" style=\"width:250px;\" /></td>
		<td align=\"center\">{$isShowText}</td>
		<td align=\"center\"><input name=\"sSort[]\" type=\"text\" value=\"99\" style=\"width:40px;\" />
		<input name=\"sModu[]\" type=\"hidden\" value=\"7\" />
		<input name=\"sNCid[{$ni}]\" type=\"hidden\" value=\"0\" />
		<input name=\"sHURL[]\" type=\"hidden\" value=\"\" />
		<input name=\"sDURL[]\" type=\"hidden\" value=\"\" />
		</td></tr>";				
	}
?>  
	<tr class="odd">
    <td height="25" align="center"><strong>导航栏下拉菜单设置：</strong></td>
    <td colspan="3">
		<input name="isDown" type="checkbox" id="isDown" value="yes" <?php if($CONFIG_NAVIGATION[0] == 1) echo 'checked="checked"';?> /> 是否开启导航栏下拉菜单功能<br />
		下拉菜单上部偏移量：<input name="menu_top" id="menu_top" type="text" value="<?php echo $CONFIG_NAVIGATION[1]; ?>" style="width:40px;" /> Px，调节菜单与按钮之间的位置，可以用负数<br />
		下拉菜单左部偏移量：<input name="menu_left" id="menu_left" type="text" value="<?php echo $CONFIG_NAVIGATION[2]; ?>" style="width:40px;" /> Px，调节菜单与按钮之间的位置，可以用负数<br />
		下拉菜单的样式及布局可以在<a href="TemplateUpDate.php?dir=<?php echo $Webtemplates[$Lang-1] ?>&File=component_top_menu.html">模板管理</a>中进行修改。
	</td>
    </tr>
   <tr class="odd">
    <td height="40" colspan="4" align="center"><input type="submit" value=" 修改/更新导航栏" style="width:150px; height:35px;" /></td>
    </tr>
</table>
</form>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="6">
	<tr class="Notodd">
		<td style="color:#333333; line-height:20px;">
		注：1、自定义导航请填写导航栏名称及链接地址，中间以"|"隔开。如："我的论坛|http://bbs.songcms.com"<br />
		　　2、自定义导航栏个数在"系统高级参数设定"中修改。
		</td>
	</tr>
</table>  
</body>
</html>
